<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>Insert title here</title>
		<script type="text/javascript">
			function convert_long() {
				
				// 获取输入的长度
				var lengthValue = document.getElementById("length").value;
				
				// 获取从什么单位
				var $from = document.getElementById("from");
				var fromIndex = $from.selectedIndex;
				var fromValue = $from.options[fromIndex].value;
				if (fromValue == '纳米(nm)') {
					lengthValue = lengthValue;
				} else if (fromValue == '微米(μm)') {
					lengthValue *= 1000;
				} else if (fromValue == '毫米(mm)') {
					lengthValue *= (1000*1000);
				} else if (fromValue == '厘米(cm)') {
					lengthValue *= (1000*1000*10);
				} else if (fromValue == '分米(dm)') {
					lengthValue *= (1000*1000*10*10);
				} else if (fromValue == '米(m)') {
					lengthValue *= (1000*1000*10*100);
				} else if (fromValue == '千米/公里(km)') {
					lengthValue *= (1000*1000*10*100000);
				}
				
				// 获取到什么单位
				var $to = document.getElementById("to");
				var toIndex = $to.selectedIndex;
				var toValue = $to.options[toIndex].value;
				
				var target = 0;
				if (toValue == '纳米(nm)') {
					target = lengthValue;
				} else if (toValue == '微米(μm)') {
					target = lengthValue / 1000;
				} else if (toValue == '毫米(mm)') {
					target = lengthValue / (1000*1000);
				} else if (toValue == '厘米(cm)') {
					target = lengthValue /(1000*1000*10);
				} else if (toValue == '分米(dm)') {
					target = lengthValue / (1000*1000*10*10);
				} else if (toValue == '米(m)') {
					target = lengthValue / (1000*1000*10*100);
				} else if (toValue == '千米/公里(km)') {
					target = lengthValue / (1000*1000*10*100000);
				}
				
				document.getElementById('result').value = target;
				
			}
		</script>
		<style>
			html{
				background-color: rgb(80,44,108);
			}
			div{
				background-color: rgb(80,44,108);
				opacity: 0.9;
			}
			#a{
				font-size: 30px;
				margin-bottom: 5px;
				padding: 10px;
			}
			#d{
				padding: 10px;
			}
			#b{
				padding: 2%;
			}
			#db{
				margin-left: 20px;
			}
			.tx{
				font-size: 20px;
				padding: 10px;
			}
		</style>
	</head>
	<body>
		<div id="a" class="tx" align="center">
			长度的换算
		</div>
		
		<div id="b" align="center">
			<font id="ba" class="tx">长度：</font><input type="text" id="length">
			<font id="bb" class="tx">从：</font>
				<select id="from">
					<option>纳米(nm)</option>
					<option>微米(μm)</option>
					<option>毫米(mm)</option>
					<option>厘米(cm)</option>
					<option>分米(dm)</option>
					<option>米(m)</option>
					<option>千米/公里(km)</option>
				</select>
		</div>
		
		<div id="c" align="center">
			<font id="ca" class="tx" >结果：</font>
			<input type="text" disabled="disabled" id="result">	
			<font id="cb" class="tx">到：</font>
				<select id="to">
					<option>纳米(nm)</option>
					<option>微米(μm)</option>
					<option>毫米(mm)</option>
					<option>厘米(cm)</option>
					<option>分米(dm)</option>
					<option>米(m)</option>
					<option>千米/公里(km)</option>
				</select>
		</div>
		
		<div id="d" align="center">
			<button type="button" onclick="return convert_long()"  id="da">转换</button>
			<a href="../../../index.html"><button type="button"  id="db">返回</button></a>
		</div>
	</body>
</html>